<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">



  
  
    
    
  <script src="/dxl/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/dxl/lib/pace/pace-theme-minimal.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/dxl/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/dxl/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/dxl/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/dxl/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/dxl/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/dxl/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/dxl/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="面试题,">










<meta name="description" content="一、需要用到的模块和知识123451框架：flask、mui2、数据库：	Mongodb redis3、引用的接口：	百度ai	图灵机器人  二、需求分析1、产生背景 1现在社会压力大。父母没有时间陪伴孩子的较少，一些家庭无法给孩子一个健康的成长环境，不能够与孩子维持良好的亲情关系。  2、实现的功能 123451、外性上：符合幼儿的审美2、建立丰富的知识库，解决孩子的为什么3、实现父母与孩子的通">
<meta name="keywords" content="面试题">
<meta property="og:type" content="article">
<meta property="og:title" content="智能玩具项目复习">
<meta property="og:url" content="http://yoursite.com/2019/09/20/【面试题】04-2智能玩具开发 - 副本/index.html">
<meta property="og:site_name" content="我的快乐时光">
<meta property="og:description" content="一、需要用到的模块和知识123451框架：flask、mui2、数据库：	Mongodb redis3、引用的接口：	百度ai	图灵机器人  二、需求分析1、产生背景 1现在社会压力大。父母没有时间陪伴孩子的较少，一些家庭无法给孩子一个健康的成长环境，不能够与孩子维持良好的亲情关系。  2、实现的功能 123451、外性上：符合幼儿的审美2、建立丰富的知识库，解决孩子的为什么3、实现父母与孩子的通">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-09-20T12:08:01.806Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="智能玩具项目复习">
<meta name="twitter:description" content="一、需要用到的模块和知识123451框架：flask、mui2、数据库：	Mongodb redis3、引用的接口：	百度ai	图灵机器人  二、需求分析1、产生背景 1现在社会压力大。父母没有时间陪伴孩子的较少，一些家庭无法给孩子一个健康的成长环境，不能够与孩子维持良好的亲情关系。  2、实现的功能 123451、外性上：符合幼儿的审美2、建立丰富的知识库，解决孩子的为什么3、实现父母与孩子的通">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/dxl/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":true,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2019/09/20/【面试题】04-2智能玩具开发 - 副本/">





  <title>智能玩具项目复习 | 我的快乐时光</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/dxl/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">我的快乐时光</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/dxl/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/dxl/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/dxl/2019/09/20/【面试题】04-2智能玩具开发 - 副本/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content>
      <meta itemprop="description" content>
      <meta itemprop="image" content="/dxl/images/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="我的快乐时光">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">智能玩具项目复习</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-09-20T20:05:12+08:00">
                2019-09-20
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/dxl/categories/面试题/" itemprop="url" rel="index">
                    <span itemprop="name">面试题</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/dxl/2019/09/20/【面试题】04-2智能玩具开发 - 副本/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count valine-comment-count" data-xid="/dxl/2019/09/20/【面试题】04-2智能玩具开发 - 副本/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv">本文总阅读量
            <span class="busuanzi-value" id="busuanzi_value_page_pv"></span>次
            </span>
          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="一、需要用到的模块和知识"><a href="#一、需要用到的模块和知识" class="headerlink" title="一、需要用到的模块和知识"></a>一、需要用到的模块和知识</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">1框架：flask、mui</span><br><span class="line">2、数据库：	Mongodb redis</span><br><span class="line">3、引用的接口：</span><br><span class="line">	百度ai</span><br><span class="line">	图灵机器人</span><br></pre></td></tr></table></figure>

<h2 id="二、需求分析"><a href="#二、需求分析" class="headerlink" title="二、需求分析"></a>二、需求分析</h2><p>1、产生背景</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">现在社会压力大。父母没有时间陪伴孩子的较少，一些家庭无法给孩子一个健康的成长环境，不能够与孩子维持良好的亲情关系。</span><br></pre></td></tr></table></figure>

<p>2、实现的功能</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">1、外性上：符合幼儿的审美</span><br><span class="line">2、建立丰富的知识库，解决孩子的为什么</span><br><span class="line">3、实现父母与孩子的通讯，成为孩子与父母沟通的桥梁，培养感情</span><br><span class="line">4、父母可以选择建立儿童的社交圈。 玩具之间</span><br><span class="line">5、父母可以了解玩具的动向，帮珠孩子健康成长 ---app可以监控玩具的动向</span><br></pre></td></tr></table></figure>

<p>3、意义</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">	通过该玩具可以为孩子营造一个健康的成长环境，增加父母与孩子之间的亲情。</span><br><span class="line"><span class="number">1</span>、解决留守儿童越是父母的关爱</span><br><span class="line"><span class="number">2</span>、建立父母与儿童的桥梁渠道</span><br><span class="line"><span class="number">3</span>、增加父母与子女的互动频率从而维系亲情</span><br></pre></td></tr></table></figure>

<p>复习补充</p>
<p>4、项目需求</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">1、幼教内容</span><br><span class="line">2、产生APP与玩具之间的互动</span><br><span class="line">3、陪聊</span><br><span class="line">4、解决成长中遇到的问题</span><br><span class="line">5、幼儿社交圈</span><br></pre></td></tr></table></figure>

<p>5、项目功能</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">1、app</span><br><span class="line">	审核幼教内容：内容来源，知名内容提交商</span><br><span class="line">	绑定玩具：扫描二维码 控制玩具通讯录</span><br><span class="line">	控制玩具播放内容</span><br><span class="line">	沟通聊天对话 语音tm通讯</span><br><span class="line">	 	-websocket 消息通知</span><br><span class="line">	 	-flask send_file 获取消息的内</span><br><span class="line">2、 toy</span><br><span class="line">	点播歌曲</span><br><span class="line">	对话 app toy </span><br><span class="line">		- websocket  消息通知 flask send——file获取</span><br><span class="line">		- im语音通讯</span><br><span class="line">			1.录音</span><br><span class="line">			2.录音文件 通过httppost上传语音文件</span><br><span class="line">			3.服务器保存语音文件</span><br><span class="line">			4.通过websocket发送消息通知，通知包含着当前消息的文件名</span><br><span class="line">			5.通过文件获取消息内容</span><br><span class="line">	智能语音对话 ai对话 第三方api图灵机器人</span><br><span class="line">	无屏社交方式 通过语音来识别联系人</span><br><span class="line">3、后台智能部分</span><br><span class="line">	语音识别 ASR 百度API</span><br><span class="line">	语音合成 tts 百度 AI</span><br><span class="line">	自然语言处理：</span><br><span class="line">		百度AI:</span><br><span class="line">			Gensim稀疏矩阵相似度</span><br><span class="line">			GensimLsimedel</span><br><span class="line">			pypingyin稀疏矩阵相似度</span><br><span class="line">			jieba稀疏矩阵相似度</span><br></pre></td></tr></table></figure>

<h2 id="三、数据库"><a href="#三、数据库" class="headerlink" title="三、数据库"></a>三、数据库</h2><h3 id="3-1有哪些表"><a href="#3-1有哪些表" class="headerlink" title="3.1有哪些表"></a>3.1有哪些表</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>、user:针对父母</span><br><span class="line"> <span class="comment">#id 昵称 密码 绑定玩具的id[、]、好友列表[&#123;好友id、备注、聊天记录id（找对应的聊天纪律），好友类型&#125;&#123;&#125;]</span></span><br><span class="line"><span class="number">2</span>、toys：针对孩子</span><br><span class="line"><span class="comment">#id 、昵称 绑定的用户 好友列表[&#123;好友id、备注、聊天记录id（找对应的聊天纪律），好友类型&#125;&#123;&#125;]</span></span><br><span class="line"><span class="number">3</span>、request；好友请求：针对玩具与玩具、玩具与用户相互加好友信息的储存</span><br><span class="line"><span class="comment">#双方的id、记录的状态、发起好友方的类型、</span></span><br><span class="line"><span class="number">4</span>、Devices ：</span><br><span class="line"><span class="comment">#设备的唯一表示，二维码</span></span><br><span class="line"><span class="number">5</span>、content <span class="comment">#幼儿内容数据表</span></span><br><span class="line"><span class="comment"># 储存音乐信息</span></span><br><span class="line"><span class="number">6</span>、chats ：储存聊天信息</span><br><span class="line"><span class="number">7</span>、redis、存储未读消息信息数</span><br></pre></td></tr></table></figure>

<h3 id="3-2Users"><a href="#3-2Users" class="headerlink" title="3.2Users"></a>3.2Users</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">	<span class="string">"_id"</span> : ObjectId(<span class="string">"5c9d8da3ea512d2048826260"</span>),  <span class="comment">//自动生成ID</span></span><br><span class="line">	<span class="string">"username"</span> : <span class="string">"asdf"</span>, <span class="comment">//用户名</span></span><br><span class="line">	<span class="string">"password"</span> : <span class="string">"962012d09b8170d912f0669f6d7d9d07"</span>, <span class="comment">//密码</span></span><br><span class="line">	<span class="string">"nickname"</span> : <span class="string">"DragonFire"</span>, <span class="comment">// 用户昵称</span></span><br><span class="line">	<span class="string">"gender"</span> : <span class="string">"2"</span>, <span class="comment">// 用户性别</span></span><br><span class="line">	<span class="string">"avatar"</span> : <span class="string">"baba.jpg"</span>, <span class="comment">// 用户头像 男=="baba.jpg" 女=="mama.jpg"</span></span><br><span class="line">	<span class="string">"bind_toys"</span> : [ <span class="comment">// 用户绑定的玩具ID(string)</span></span><br><span class="line">		<span class="string">"5ca17c7aea512d26281bcb8d"</span>,</span><br><span class="line">		<span class="string">"5ca17f85ea512d215cd9b079"</span></span><br><span class="line">	], </span><br><span class="line">	<span class="string">"friend_list"</span> : [ <span class="comment">// 用户的通讯录列表</span></span><br><span class="line">		&#123; <span class="comment">// 通讯录信息</span></span><br><span class="line">			<span class="string">"friend_id"</span> : <span class="string">"5ca17c7aea512d26281bcb8d"</span>, <span class="comment">// 好友id</span></span><br><span class="line">			<span class="string">"friend_nick"</span> : <span class="string">"背背"</span>, <span class="comment">// 好友的昵称</span></span><br><span class="line">			<span class="string">"friend_rem  ark"</span> : <span class="string">"臭屎蛋儿"</span>, <span class="comment">// 好友备注</span></span><br><span class="line">			<span class="string">"friend_avatar"</span> : <span class="string">"toy.jpg"</span>, <span class="comment">// 好友头像</span></span><br><span class="line">			<span class="string">"friend_chat"</span> : <span class="string">"5ca17c7aea512d26281bcb8c"</span>, <span class="comment">// 私聊窗口ID 聊天数据表对应值</span></span><br><span class="line">			<span class="string">"friend_type"</span> : <span class="string">"toy"</span> <span class="comment">// 好友类型</span></span><br><span class="line">		&#125;,</span><br><span class="line">		&#123;</span><br><span class="line">			<span class="string">"friend_id"</span> : <span class="string">"5ca17f85ea512d215cd9b079"</span>,</span><br><span class="line">			<span class="string">"friend_nick"</span> : <span class="string">"圆圆"</span>,</span><br><span class="line">			<span class="string">"friend_remark"</span> : <span class="string">"小粪球儿"</span>,</span><br><span class="line">			<span class="string">"friend_avatar"</span> : <span class="string">"toy.jpg"</span>,</span><br><span class="line">			<span class="string">"friend_chat"</span> : <span class="string">"5ca17f85ea512d215cd9b078"</span>,</span><br><span class="line">			<span class="string">"friend_type"</span> : <span class="string">"toy"</span></span><br><span class="line">		&#125;</span><br><span class="line">	]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="3-3-Toys"><a href="#3-3-Toys" class="headerlink" title="3.3 Toys"></a>3.3 Toys</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">	<span class="string">"_id"</span> : ObjectId(<span class="string">"5ca17f85ea512d215cd9b079"</span>), // 自动生成ID</span><br><span class="line">	<span class="string">"toy_name"</span> : <span class="string">"小粪球儿"</span>, // 玩具的昵称</span><br><span class="line">	<span class="string">"baby_name"</span> : <span class="string">"圆圆"</span>, // 玩具主人的昵称</span><br><span class="line">	<span class="string">"device_key"</span> : <span class="string">"afc59916257ae8a2b6ccdfb9fd273373"</span>, // 玩具的设备编号</span><br><span class="line">	<span class="string">"avatar"</span> : <span class="string">"toy.jpg"</span>, // 玩具的头像固定值 <span class="string">"toy.jpg"</span></span><br><span class="line">	<span class="string">"bind_user"</span> : <span class="string">"5c9d8da3ea512d2048826260"</span>, // 玩具的绑定用户</span><br><span class="line">	<span class="string">"friend_list"</span> : [ // 玩具通讯录信息 </span><br><span class="line">		&#123; // 与Users数据表 friend_list 结构相同</span><br><span class="line">			<span class="string">"friend_id"</span> : <span class="string">"5c9d8da3ea512d2048826260"</span>,</span><br><span class="line">			<span class="string">"friend_nick"</span> : <span class="string">"DragonFire"</span>,</span><br><span class="line">			<span class="string">"friend_remark"</span> : <span class="string">"爸爸"</span>,</span><br><span class="line">			<span class="string">"friend_avatar"</span> : <span class="string">"baba.jpg"</span>,</span><br><span class="line">			<span class="string">"friend_chat"</span> : <span class="string">"5ca17f85ea512d215cd9b078"</span>,</span><br><span class="line">			<span class="string">"friend_type"</span> : <span class="string">"app"</span></span><br><span class="line">		&#125;,</span><br><span class="line">		&#123;</span><br><span class="line">			<span class="string">"friend_id"</span> : <span class="string">"5ca17c7aea512d26281bcb8d"</span>,</span><br><span class="line">			<span class="string">"friend_nick"</span> : <span class="string">"臭屎蛋儿"</span>,</span><br><span class="line">			<span class="string">"friend_remark"</span> : <span class="string">"蛋蛋的忧伤"</span>,</span><br><span class="line">			<span class="string">"friend_avatar"</span> : <span class="string">"toy.jpg"</span>,</span><br><span class="line">			<span class="string">"friend_chat"</span> : <span class="string">"5ca5e789ea512d2e544da015"</span>,</span><br><span class="line">			<span class="string">"friend_type"</span> : <span class="string">"toy"</span></span><br><span class="line">		&#125;</span><br><span class="line">	]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="3-4-Request"><a href="#3-4-Request" class="headerlink" title="3.4 Request"></a>3.4 Request</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">	<span class="string">"_id"</span> : ObjectId(<span class="string">"5ca5bfbaea512d269449ed1b"</span>), // 自动生成ID</span><br><span class="line">	<span class="string">"add_user"</span> : <span class="string">"5ca17c7aea512d26281bcb8d"</span>, // 发起好友申请方</span><br><span class="line">	<span class="string">"toy_id"</span> : <span class="string">"5ca17f85ea512d215cd9b079"</span>, // 收到好友申请方</span><br><span class="line">	<span class="string">"add_type"</span> : <span class="string">"toy"</span>, // 发起方的用户类型 app/toy</span><br><span class="line">	<span class="string">"req_info"</span> : <span class="string">"我是仇视单"</span>, // 请求信息</span><br><span class="line">	<span class="string">"remark"</span> : <span class="string">"园园"</span>, // 发起方对接收方的好友备注</span><br><span class="line">	<span class="string">"avatar"</span> : <span class="string">"toy.jpg"</span>, // 发起方的头像</span><br><span class="line">	<span class="string">"nickname"</span> : <span class="string">"背背"</span>, // 发起方的名称</span><br><span class="line">	<span class="string">"status"</span> : <span class="number">1</span>, // 请求状态 <span class="number">1</span>同意 <span class="number">0</span>未处理 <span class="number">2</span>拒绝</span><br><span class="line">	<span class="string">"toy_name"</span> : <span class="string">"圆圆"</span> // 接收方的名称</span><br></pre></td></tr></table></figure>

<h3 id="3-5-Devices"><a href="#3-5-Devices" class="headerlink" title="3.5 Devices"></a>3.5 Devices</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">	&quot;_id&quot; : ObjectId(&quot;5c9d9e72ea512d1ae49f002e&quot;), // 自动生成ID</span><br><span class="line">	&quot;device_key&quot; : &quot;afc59916257ae8a2b6ccdfb9fd273373&quot; // 设备的唯一编号 二维码信息</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="3-6-Content"><a href="#3-6-Content" class="headerlink" title="3.6 Content"></a>3.6 Content</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">	&quot;_id&quot; : ObjectId(&quot;5c9c53a7ea512d282495a499&quot;), // 自动生成ID</span><br><span class="line">	&quot;music&quot; : &quot;2f1fe658-d018-4aaf-a088-bdaaeed29745.mp3&quot;, // 内容文件名</span><br><span class="line">	&quot;cover&quot; : &quot;2f1fe658-d018-4aaf-a088-bdaaeed29745.jpg&quot;, // 内容图像</span><br><span class="line">	&quot;title&quot; : &quot;一只哈巴狗&quot;, // 内容名称</span><br><span class="line">    &quot;zhuanji&quot;: &quot;以哦签领以&quot; // 专辑名称</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="3-7-Chats"><a href="#3-7-Chats" class="headerlink" title="3.7 Chats"></a>3.7 Chats</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">	&quot;_id&quot; : ObjectId(&quot;5ca5e789ea512d2e544da015&quot;), //自动生成ID</span><br><span class="line">	&quot;user_list&quot; : [ // 用户列表 数据此聊天窗口的用户</span><br><span class="line">		&quot;5ca17f85ea512d215cd9b079&quot;, // toy</span><br><span class="line">		&quot;5ca17c7aea512d26281bcb8d&quot;// app</span><br><span class="line">	],</span><br><span class="line">	&quot;chat_list&quot; : [ // 聊天内容列表</span><br><span class="line">		&#123;</span><br><span class="line">			&quot;from_user&quot; : &quot;5ca17c7aea512d26281bcb8d&quot;, // 信息发送方ID</span><br><span class="line">			&quot;to_user&quot; : &quot;5ca17f85ea512d215cd9b079&quot;, // 信息接收方ID</span><br><span class="line">			&quot;chat&quot; : &quot;c22b9edd-4e7a-4eee-94e7-b239a90b9b16.wav&quot;, // 语音消息文件名</span><br><span class="line">			&quot;createTime&quot; : 1554376821.5634897 // 聊天创建时间</span><br><span class="line">		&#125;</span><br><span class="line">    ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="四、业务逻辑分析与处理（Api）"><a href="#四、业务逻辑分析与处理（Api）" class="headerlink" title="四、业务逻辑分析与处理（Api）"></a>四、业务逻辑分析与处理（Api）</h2><h3 id="4-1-用户（登录、注册）"><a href="#4-1-用户（登录、注册）" class="headerlink" title="4.1 用户（登录、注册）"></a>4.1 用户（登录、注册）</h3><p>1、注册（reg）用于App用户注册</p>
<p>API</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">URL地址:	 /reg</span><br><span class="line">请求方式:	POST</span><br><span class="line">请求协议:</span><br><span class="line">    </span><br><span class="line">请求：</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">	<span class="string">"username"</span>:username,</span><br><span class="line">	<span class="string">"password"</span>:password,</span><br><span class="line">	<span class="string">"nickname"</span>:nickname,</span><br><span class="line">	<span class="string">"gender"</span>:gender,</span><br><span class="line">	<span class="string">"avatar"</span>:avatar.jpg</span><br><span class="line">&#125;</span><br><span class="line">响应：</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">	<span class="string">"code"</span>:<span class="number">0</span>,</span><br><span class="line">	<span class="string">"msg"</span>:<span class="string">"注册成功"</span>,</span><br><span class="line">	<span class="string">"data"</span>:&#123;&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>分析</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>、接受页面传来的注册信息</span><br><span class="line"><span class="number">2</span>、判断用户表里是否有该注册信息</span><br><span class="line">	没有：</span><br><span class="line">    	 分析user表结构</span><br><span class="line">    	 按照数据表的格式整合数据写入数据库</span><br><span class="line">		 整合html页面所需要的数据类型</span><br><span class="line">	有：整合html页面所需要的数据类型</span><br><span class="line"><span class="number">3</span>、返回数据类型</span><br></pre></td></tr></table></figure>

<p>2、登录(login)</p>
<p>用于 App 用户登录</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">URL地址:	 /login</span><br><span class="line">请求方式:	POST </span><br><span class="line">请求协议: </span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">	<span class="string">"username"</span>:username,</span><br><span class="line">	<span class="string">"password"</span>:password</span><br><span class="line">&#125;</span><br><span class="line">响应数据:</span><br><span class="line"></span><br><span class="line">&#123;</span><br><span class="line">	<span class="string">"code"</span>:<span class="number">0</span>,</span><br><span class="line">	<span class="string">"msg"</span>:<span class="string">"登录成功"</span>,</span><br><span class="line">	<span class="string">"data"</span>:</span><br><span class="line">	&#123;</span><br><span class="line">        <span class="string">"_id"</span> : <span class="string">"5c8f582f268d7942f44c6703"</span>,</span><br><span class="line">        <span class="string">"username"</span> : <span class="string">"DragonFire"</span>,</span><br><span class="line">        <span class="string">"gender"</span> : <span class="string">"2"</span>,</span><br><span class="line">        <span class="string">"nickname"</span> : <span class="string">"厉害了我的哥"</span>,</span><br><span class="line">        <span class="string">"avatar"</span> : <span class="string">"baba.jpg"</span>,</span><br><span class="line">        <span class="string">"friend_list"</span> : [],</span><br><span class="line">        <span class="string">"bind_toy"</span> : []</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>分析</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>、将html传过来的数据装换成字典</span><br><span class="line"><span class="number">2</span>、查看用户表里是否有对应的记录</span><br><span class="line"><span class="number">3</span>、返回前段所需要的数据类型</span><br><span class="line">	CODE:<span class="number">0</span>登录成功 </span><br><span class="line">	CODE:<span class="number">1</span>登录失败</span><br><span class="line"><span class="number">4</span> /html收到 CODE:<span class="number">0</span>登录成功 </span><br><span class="line">	前端将登录信息进行缓存</span><br><span class="line">	window.localStorage.setItem(<span class="string">"user_id"</span>,data.DATA._id);</span><br><span class="line">	发起新的url</span><br><span class="line">	url: <span class="string">'user_info.html'</span>,</span><br></pre></td></tr></table></figure>

<p>3、自动化登录（authlogin）</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">打开app</span><br><span class="line">	首先进行判断window.localStorage.getItem(<span class="string">"user_id"</span>)：</span><br><span class="line">	有数据发起自动登录请求</span><br><span class="line"><span class="number">1</span>、python</span><br><span class="line"><span class="number">2</span>、查看用户表里是否有对应的记录</span><br><span class="line"><span class="number">3</span>、返回前段所需要的数据类型（包含未读消息的数目）</span><br><span class="line">	CODE:<span class="number">0</span>登录成功</span><br><span class="line">	CODE:<span class="number">0</span>登录失败</span><br><span class="line"><span class="number">4</span> /html 收到数据 并将未读的消息数渲染到相应的页面</span><br></pre></td></tr></table></figure>

<h3 id="4-2设备"><a href="#4-2设备" class="headerlink" title="4.2设备"></a>4.2设备</h3><p>1、扫描二维码(Qr)</p>
<p>API</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line">用于App扫描Toy对应二维码进行识别</span><br><span class="line"></span><br><span class="line">URL地址:	 /scan_qr</span><br><span class="line">请求方式:	POST</span><br><span class="line">请求协议:</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">    <span class="string">"device_key"</span>:device_key, //app扫描二维码后获取到的device_key</span><br><span class="line">&#125;</span><br><span class="line">响应数据:</span><br><span class="line">JSON:</span><br><span class="line">//<span class="number">1.</span>二维码扫描成功并且设备未进行绑定</span><br><span class="line">&#123;</span><br><span class="line">	<span class="string">"code"</span>:<span class="number">0</span>,</span><br><span class="line">	<span class="string">"msg"</span>:<span class="string">"二维码扫描成功"</span>,</span><br><span class="line">	<span class="string">"data"</span>:</span><br><span class="line">	&#123;</span><br><span class="line">        <span class="string">"device_key"</span>:device_key</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">//<span class="number">2.</span>二维码扫描失败,扫描的条码不是设备库中存在的</span><br><span class="line">&#123;</span><br><span class="line">	<span class="string">"code"</span>:<span class="number">1</span>,</span><br><span class="line">	<span class="string">"msg"</span>:<span class="string">"请扫描玩具二维码"</span>,</span><br><span class="line">	<span class="string">"data"</span>:&#123;&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">//<span class="number">3.</span>二维码扫描成功,但设备已经进行绑定</span><br><span class="line">&#123;</span><br><span class="line">	<span class="string">"code"</span>:<span class="number">2</span>,</span><br><span class="line">	<span class="string">"msg"</span>:<span class="string">"设备已经进行绑定"</span>,</span><br><span class="line">	<span class="string">"data"</span>:</span><br><span class="line">	&#123;</span><br><span class="line">        <span class="string">"toy_id"</span>:toy_id</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>分析：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>、分析该二维码字段是否是我们的设备，不是返回数据<span class="comment">#"CODE": 1,请扫描玩具的二维码</span></span><br><span class="line"><span class="number">2</span>、判断玩具是否在已绑定的玩具列表里、在进行玩具的绑定操作 <span class="string">"CODE"</span>: <span class="number">0</span>,绑定操作</span><br><span class="line"><span class="number">3</span>、<span class="comment"># 不在 返回 "CODE": 2,添加好友操作</span></span><br></pre></td></tr></table></figure>

<p>2、玩具与用户的绑定（bindtoy）</p>
<p>api</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">URL地址:	 /bind_toy</span><br><span class="line">请求方式:	POST</span><br><span class="line">请求协议:</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">    &quot;toy_name&quot;:toy_name, //toy名称</span><br><span class="line">    &quot;baby_name&quot;:baby_name, //toy所属主人名称</span><br><span class="line">    &quot;remark&quot;:remark, //toy主人对App用户的称呼</span><br><span class="line">    &quot;user_id&quot;:user_id,//绑定Toy的App用户Id</span><br><span class="line">    &quot;device_key&quot;:device_key, //设备唯一编码device_key</span><br><span class="line">&#125;</span><br><span class="line">响应数据:</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">	&quot;code&quot;:0,</span><br><span class="line">	&quot;msg&quot;:&quot;绑定完成&quot;,</span><br><span class="line">	&quot;data&quot;:&#123;&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">	分析设计之初时考虑到了app绑定玩具成功，双方自动添加为好友，添加好友是双向的过程需要双方互加名片</span><br><span class="line">第一步：创建玩具，并添加app的好友名片</span><br><span class="line"><span class="number">1</span>、获取玩具要绑定的app对象</span><br><span class="line"><span class="number">2</span>、通过分析toys得知还需要聊天纪律表对应的id纪律创建chats表</span><br><span class="line"><span class="number">3</span>、组合数据结构、创建玩具获得相应的id</span><br><span class="line">第二部：用户绑定APP、</span><br><span class="line"><span class="number">1</span>、user的 bind_toys、friend_list添加对应的数据类型</span><br><span class="line"><span class="number">2</span>、更新user表，进行数据信息的保存</span><br><span class="line">第三部：</span><br><span class="line">更新聊天纪律表（新添加了user-list）</span><br><span class="line">第四部：</span><br><span class="line">返回绑定成功的信息并打开toy_manager页面</span><br><span class="line"><span class="comment">#1、获取双方的信息、根据玩具可以按到用户信息</span></span><br><span class="line"><span class="comment">#2、构建聊天记录id</span></span><br><span class="line"><span class="comment">#3、玩具添加用户为好友，用户添加玩具为好友。跟新数据库</span></span><br><span class="line"><span class="comment">#4、跟新聊天表</span></span><br></pre></td></tr></table></figure>

<p>2、App获取绑定Toy信息接口</p>
<p>用于App获取已经绑定的设备和创建过Toy信息</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><span class="line">URL地址:	 /toy_list</span><br><span class="line">请求方式:	POST</span><br><span class="line">请求协议:</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">    <span class="string">"_id"</span>:user_id //App用户Id</span><br><span class="line">&#125;</span><br><span class="line">响应数据:</span><br><span class="line">&#123;</span><br><span class="line">	<span class="string">"code"</span>:<span class="number">0</span>,</span><br><span class="line">	<span class="string">"msg"</span>:<span class="string">"获取Toy列表"</span>,</span><br><span class="line">	<span class="string">"data"</span>:</span><br><span class="line">	[</span><br><span class="line">		&#123;</span><br><span class="line">            <span class="string">"_id"</span> : ObjectId(<span class="string">"5bcdaaa6268d794ec8af3fa2"</span>),</span><br><span class="line">            <span class="string">"device_key"</span> : <span class="string">"bc557bcc9570069a494a64eb38698d35"</span>,</span><br><span class="line">            <span class="string">"bind_user"</span> : <span class="string">"5bcda858268d796fc8d3e3de"</span>,</span><br><span class="line">            <span class="string">"toy_name"</span> : <span class="string">"蛋蛋"</span>,</span><br><span class="line">            <span class="string">"avatar"</span> : <span class="string">"toy.jpg"</span>,</span><br><span class="line">            <span class="string">"baby_name"</span> : <span class="string">"臭屎蛋儿"</span>,</span><br><span class="line">            <span class="string">"gender"</span> : <span class="string">"1"</span>,</span><br><span class="line">            <span class="string">"friend_list"</span> : [</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="string">"friend_nickname"</span> : <span class="string">"淫王"</span>,</span><br><span class="line">                    <span class="string">"friend_avatar"</span> : <span class="string">"girl.jpg"</span>,</span><br><span class="line">                    <span class="string">"friend_remark"</span> : <span class="string">"爸爸"</span>,</span><br><span class="line">                    <span class="string">"friend_chat"</span> : <span class="string">"5bcdaaa6268d794ec8af3fa1"</span></span><br><span class="line">                &#125;</span><br><span class="line">            ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="string">"_id"</span> : ObjectId(<span class="string">"5bcdaa6f268d794ec8af3fa0"</span>),</span><br><span class="line">            <span class="string">"device_key"</span> : <span class="string">"a195ac8014fb069676835a78d300f8a3"</span>,</span><br><span class="line">            <span class="string">"bind_user"</span> : <span class="string">"5bcda858268d796fc8d3e3de"</span>,</span><br><span class="line">            <span class="string">"toy_name"</span> : <span class="string">"球球"</span>,</span><br><span class="line">            <span class="string">"avatar"</span> : <span class="string">"toy.jpg"</span>,</span><br><span class="line">            <span class="string">"baby_name"</span> : <span class="string">"小粪球儿"</span>,</span><br><span class="line">            <span class="string">"gender"</span> : <span class="string">"1"</span>,</span><br><span class="line">            <span class="string">"friend_list"</span> : [</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="string">"friend_nickname"</span> : <span class="string">"淫王"</span>,</span><br><span class="line">                    <span class="string">"friend_avatar"</span> : <span class="string">"girl.jpg"</span>,</span><br><span class="line">                    <span class="string">"friend_remark"</span> : <span class="string">"爸爸"</span>,</span><br><span class="line">                    <span class="string">"friend_chat"</span> : <span class="string">"5bcdaa6f268d794ec8af3f9f"</span></span><br><span class="line">                &#125;</span><br><span class="line">            ]</span><br><span class="line">        &#125;</span><br><span class="line">	]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">点击管理我的玩具页面，调转页面后首先发起toy_list获取相应的数据信息展示到页面</span><br><span class="line"><span class="number">1</span>、获取前段的值uid</span><br><span class="line"><span class="number">2</span>、在玩具表通过bind_user字段找到用户所拥有的玩具</span><br><span class="line"><span class="number">3</span>、将玩具信息进行数据整合返回给前段</span><br></pre></td></tr></table></figure>

<p>3、get_qr(获取二维码)</p>
<p>用于App获取二维码图片</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">URL地址:	 /get_qr/&lt;qrname&gt;.mp3</span><br><span class="line">请求方式:	GET</span><br><span class="line">请求协议:	无</span><br><span class="line">响应数据:	数据流</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">前段点击智能玩具二维码时，发起get_qr请求</span><br><span class="line">1、get请求</span><br><span class="line">2、获取二维码标识</span><br><span class="line">3、找到对应的二维码图片以数据流的形式进行返回</span><br><span class="line">4、注意事项：</span><br><span class="line">get请求的传参</span><br></pre></td></tr></table></figure>

<h3 id="4-3设备启动登录接口"><a href="#4-3设备启动登录接口" class="headerlink" title="4.3设备启动登录接口:"></a>4.3设备启动登录接口:</h3><p>用于设备启动后验证身份信息</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">URL地址:	 /open_toy</span><br><span class="line">请求方式:	POST</span><br><span class="line">请求协议:</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">    &quot;device_key&quot;:device_key, //设备中写定的DeviceKey</span><br><span class="line">&#125;</span><br><span class="line">响应数据:</span><br><span class="line">JSON:</span><br><span class="line">//1.设备处于绑定状态,正常启动</span><br><span class="line">&#123;</span><br><span class="line">	&quot;code&quot;:0,</span><br><span class="line">	&quot;music&quot;:&quot;Success.mp3&quot;,</span><br><span class="line">	&quot;toy_id&quot;:toy_id,</span><br><span class="line">	&quot;name&quot;:toy_name</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">//2.设备未绑定</span><br><span class="line">&#123;</span><br><span class="line">	&quot;code&quot;:2,</span><br><span class="line">	&quot;music&quot;:&quot;Nolic.mp3&quot;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">//3.设备未授权</span><br><span class="line">&#123;</span><br><span class="line">	&quot;code&quot;:1,</span><br><span class="line">	&quot;music&quot;:&quot;Nobind.mp3&quot;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>、获取玩具的的标识dervice</span><br><span class="line"><span class="number">2</span>、判断标识是否在toys表里</span><br><span class="line">	在的话正常开机：</span><br><span class="line">	不在的话：是否是我们的玩具</span><br><span class="line">			是：返回请进行绑定</span><br><span class="line">			否：请扫描正确的二维码</span><br></pre></td></tr></table></figure>

<h3 id="4-4内容相关"><a href="#4-4内容相关" class="headerlink" title="4.4内容相关"></a>4.4内容相关</h3><p>1、/content_list</p>
<p>用于App首页内容资源获取</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">URL地址:	 /content_list</span><br><span class="line">请求方式:	POST</span><br><span class="line">请求协议:</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br><span class="line">响应数据：</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">	&quot;code&quot;:0,</span><br><span class="line">	&quot;msg&quot;:&quot;获取内容资源列表&quot;,</span><br><span class="line">	&quot;data&quot;:</span><br><span class="line">	[</span><br><span class="line">		&#123;</span><br><span class="line">            &quot;_id&quot; : &quot;5c8f58eb268d79173c97bac5&quot;,</span><br><span class="line">            &quot;music&quot; : &quot;21b61cc0-9292-4e51-bf58-72be8ee6f962.mp3&quot;,</span><br><span class="line">            &quot;cover&quot; : &quot;21b61cc0-9292-4e51-bf58-72be8ee6f962.jpg&quot;,</span><br><span class="line">            &quot;title&quot; : &quot;一只哈巴狗&quot;</span><br><span class="line">		&#125;,</span><br><span class="line">		&#123;</span><br><span class="line">			&quot;_id&quot; : &quot;5c8f58eb268d79173c97bac4&quot;,</span><br><span class="line">            &quot;music&quot; : &quot;aa523ebe-95f9-4641-9478-1663cc74c6a6.mp3&quot;,</span><br><span class="line">            &quot;cover&quot; : &quot;aa523ebe-95f9-4641-9478-1663cc74c6a6.jpg&quot;,</span><br><span class="line">            &quot;title&quot; : &quot;学习雷锋好榜样&quot;</span><br><span class="line">		&#125;</span><br><span class="line">	]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">点击首页按钮调转main页面发起/content_list</span><br><span class="line">主要是将音乐资源返回给html</span><br></pre></td></tr></table></figure>

<p>2、获取音乐资源get_music</p>
<p>用于App/Toy播放内容</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">URL地址:	 /get_music/&lt;musicname&gt;.mp3</span><br><span class="line">请求方式:	GET</span><br><span class="line">请求协议:	无</span><br><span class="line">响应数据:	数据流</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">根据音乐的名字找对对应的路径放回数据流</span><br></pre></td></tr></table></figure>

<p>3、获取图片资源get_cover</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">用于App获取图片资源</span><br><span class="line"></span><br><span class="line">URL地址:	 /get_cover/&lt;imagename&gt;.jpg</span><br><span class="line">请求方式:	GET</span><br><span class="line">请求协议:	无</span><br><span class="line">响应数据:	数据流</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">根据图片的名字找对对应的路径放回数据流</span><br></pre></td></tr></table></figure>

<p>4、get_chat</p>
<p>​        获取语音消息资源(用于App/Toy播放语音消息)</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">URL地址:	 /get_chat/&lt;chatname&gt;.mp3</span><br><span class="line">请求方式:	GET</span><br><span class="line">请求协议:	无</span><br><span class="line">响应数据:	数据流</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">根据录音的名字找对对应的路径放回数据流</span><br></pre></td></tr></table></figure>

<h3 id="4-5音频上传先关联"><a href="#4-5音频上传先关联" class="headerlink" title="4.5音频上传先关联"></a>4.5音频上传先关联</h3><p>1、app_uploader</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">用于App录制语音消息上传</span><br><span class="line"></span><br><span class="line">URL地址:	 /app_uploader</span><br><span class="line">请求方式:	POST</span><br><span class="line">请求协议:</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">    &quot;to_user&quot;:to_user, //语音消息接收方</span><br><span class="line">    &quot;user_id&quot;:from_user, //语音消息发送方</span><br><span class="line">    &quot;reco_file&quot;:File, //语音文件</span><br><span class="line">&#125;</span><br><span class="line">响应数据：</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">	&quot;code&quot;:0,</span><br><span class="line">	&quot;msg&quot;:&quot;上传成功&quot;,</span><br><span class="line">	&quot;data&quot;:</span><br><span class="line">	&#123;</span><br><span class="line">        &quot;filename&quot;:&quot;filename&quot;,</span><br><span class="line">        &quot;friend_type&quot;:&quot;app&quot;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">第一步：保存文件</span><br><span class="line">	<span class="number">1</span>、拿到文件对象 <span class="comment">#file = request.files.get("reco_file")</span></span><br><span class="line">    <span class="number">2</span>、拿到文件名字<span class="comment">#file_name = file.filename</span></span><br><span class="line">    <span class="number">3</span>、路径拼接<span class="comment">#ile_path = os.path.join(VOICE_PATH, file_name)</span></span><br><span class="line">    <span class="number">4</span>、保存文件<span class="comment">#file.save(file_path)</span></span><br><span class="line">第二步：转换音频格式 <span class="comment">#os.system(f"ffmpeg -i &#123;file_path&#125; &#123;file_path&#125;.mp3") </span></span><br><span class="line">第三步：见这条语音消息保存到聊天纪律表里：要带聊天双方的id</span><br><span class="line">第四步：未读消息个数提醒、将没有读取的消息保存到redis数据表里，调用存储函数	  </span><br><span class="line">第五步：语音消息提醒</span><br><span class="line">	<span class="number">1</span>、合成消息上传成功</span><br><span class="line">    <span class="number">2</span>、将合成的语音消息返回</span><br></pre></td></tr></table></figure>

<p>2、toy_uploader</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">用于Toy录制语音消息上传</span><br><span class="line"></span><br><span class="line">URL地址:	 /toy_uploader</span><br><span class="line">请求方式:	POST</span><br><span class="line">请求协议:</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">    &quot;to_user&quot;:to_user, //语音消息接收方</span><br><span class="line">    &quot;user_id&quot;:from_user, //语音消息发送方</span><br><span class="line">    &quot;friend_type&quot;:app/toy, //语音接收方的用户类型</span><br><span class="line">    &quot;reco&quot;:File, //语音文件</span><br><span class="line">&#125;</span><br><span class="line">响应数据:</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">	&quot;code&quot;:0,</span><br><span class="line">	&quot;msg&quot;:&quot;上传成功&quot;,</span><br><span class="line">	&quot;data&quot;:</span><br><span class="line">	&#123;</span><br><span class="line">        &quot;filename&quot;:&quot;filename&quot;,</span><br><span class="line">        &quot;friend_type&quot;:&quot;app&quot;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">第一步：保存文件</span><br><span class="line">	1、拿到文件对象 #file = request.files.get(&quot;reco_file&quot;)</span><br><span class="line">    2、生成文件名字#file_name = f&quot;&#123;uuid4()&#125;.mav&quot;</span><br><span class="line">    3、路径拼接#ile_path = os.path.join(VOICE_PATH, file_name)</span><br><span class="line">    4、保存文件#file.save(file_path)</span><br><span class="line">第二步：见这条语音消息保存到聊天纪律表里：要带聊天双方的id</span><br><span class="line">第四步：未读消息个数提醒、将没有读取的消息保存到redis数据表里，调用存储函数</span><br></pre></td></tr></table></figure>

<p>3 ai_uploader</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">用于Toy录制语音消息上传至AI接口</span><br><span class="line"></span><br><span class="line">URL地址:	 /ai_uploader</span><br><span class="line">请求方式:	POST</span><br><span class="line">请求协议:</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">    &quot;toy_id&quot;:toy_id, //Toy的Id</span><br><span class="line">    &quot;reco&quot;:File, //语音文件</span><br><span class="line">&#125;</span><br><span class="line">响应数据:</span><br><span class="line">JSON:</span><br><span class="line">//1.ai响应播放音乐</span><br><span class="line">&#123;</span><br><span class="line">    &quot;from_user&quot;: &quot;ai&quot;,</span><br><span class="line">    &quot;music&quot;: music_name</span><br><span class="line">&#125;</span><br><span class="line">//2.ai响应语音消息</span><br><span class="line">&#123;</span><br><span class="line">    &quot;from_user&quot;: &quot;ai&quot;, </span><br><span class="line">    &quot;chat&quot;: filename</span><br><span class="line">&#125;</span><br><span class="line">//3.ai响应主动发起消息</span><br><span class="line">&#123;</span><br><span class="line">    &quot;from_user&quot;:friend_id,</span><br><span class="line">    &quot;chat&quot;:filename,</span><br><span class="line">    &quot;friend_type&quot;:app/toy</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">第一步：保存文件</span><br><span class="line">	1、拿到文件对象 #file = request.files.get(&quot;reco_file&quot;)</span><br><span class="line">    2、生成文件名字#file_name = f&quot;&#123;uuid4()&#125;.mav&quot;</span><br><span class="line">    3、路径拼接#ile_path = os.path.join(VOICE_PATH, file_name)</span><br><span class="line">    4、保存文件#file.save(file_path)</span><br><span class="line">第二步：进行语音智能处理，返回对应的数据（详解见后文）</span><br></pre></td></tr></table></figure>

<h3 id="4-6语音消息相关"><a href="#4-6语音消息相关" class="headerlink" title="4.6语音消息相关"></a>4.6语音消息相关</h3><p>1、chat_list(用于获取历史消息)</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">用于App获取历史消息</span><br><span class="line"></span><br><span class="line">URL地址:	 /chat_list</span><br><span class="line">请求方式:	POST</span><br><span class="line">请求协议:</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">    &quot;chat_id&quot;:chat_id, //聊天窗口Id</span><br><span class="line">    &quot;to_user&quot;:user_id, //App用户Id</span><br><span class="line">    &quot;from_user&quot;:friend_id, //接收消息方Id</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">响应数据:</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">	&quot;code&quot;:0,</span><br><span class="line">	&quot;msg&quot;:&quot;查询聊天记录&quot;,</span><br><span class="line">	&quot;data&quot;:</span><br><span class="line">	[</span><br><span class="line">		&#123;</span><br><span class="line">			&quot;from_user&quot; : &quot;5c8f582f268d7942f44c6703&quot;,</span><br><span class="line">			&quot;message&quot; : &quot;1552898221960.amr.mp3&quot;,</span><br><span class="line">			&quot;create_time&quot; : 1552898225.2744157</span><br><span class="line">		&#125;,</span><br><span class="line">		&#123;</span><br><span class="line">			&quot;from_user&quot; : &quot;5c8f5853268d7942f44c6705&quot;,</span><br><span class="line">			&quot;message&quot; : &quot;ba7462dd-62a5-460c-bfab-bb64edd7c983.wav&quot;,</span><br><span class="line">			&quot;create_time&quot; : 1552899004.6702642</span><br><span class="line">		&#125;</span><br><span class="line">	]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">1、拼接查询条件user_list =[from_user,to_user]</span><br><span class="line">2、从chats表里通过对应的聊天记录进行返回</span><br></pre></td></tr></table></figure>

<p>2、recv_msg</p>
<p>用于toys收到消息提醒后</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">URL地址:	 /recv_msg</span><br><span class="line">请求方式:	POST</span><br><span class="line">请求协议:</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">    &quot;from_user&quot;:user_id/toy_id, //发送语音消息方Id</span><br><span class="line">    &quot;to_user&quot;:toy_id, //当前接收语音消息的toy_id</span><br><span class="line">&#125;</span><br><span class="line">响应数据:</span><br><span class="line">JSON:</span><br><span class="line">[</span><br><span class="line">    &#123;</span><br><span class="line">        &quot;from_user&quot; : &quot;5c8f582f268d7942f44c6703&quot;,</span><br><span class="line">        &quot;message&quot; : &quot;1552898221960.amr.mp3&quot;,</span><br><span class="line">        &quot;create_time&quot; : 1552898225.2744157</span><br><span class="line">    &#125;,</span><br><span class="line">    &#123;</span><br><span class="line">        &quot;from_user&quot; : &quot;5c8f5853268d7942f44c6705&quot;,</span><br><span class="line">        &quot;message&quot; : &quot;ba7462dd-62a5-460c-bfab-bb64edd7c983.wav&quot;,</span><br><span class="line">        &quot;create_time&quot; : 1552899004.6702642</span><br><span class="line">    &#125;</span><br><span class="line">]</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">主要是用于用toy收取未读消息</span><br><span class="line">1、首先获取未读消息的个数</span><br><span class="line">2、找到对应的聊天记录取出未读消息的个数</span><br><span class="line">3、找到对应消息的发送人的名字</span><br><span class="line">4、是否有没有读取消息的判断</span><br></pre></td></tr></table></figure>

<h3 id="4-7好友通讯相关"><a href="#4-7好友通讯相关" class="headerlink" title="4.7好友通讯相关"></a>4.7好友通讯相关</h3><p>1、friend_list</p>
<p>用于App获取好友通讯录</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">URL地址:	 /friend_list</span><br><span class="line">请求方式:	POST</span><br><span class="line">请求协议:</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">    &quot;_id&quot;:user_id, //app用户Id</span><br><span class="line">&#125;</span><br><span class="line">响应数据:</span><br><span class="line">JSON:</span><br><span class="line">//1.二维码扫描成功并且设备未进行绑定</span><br><span class="line">&#123;</span><br><span class="line">	&quot;code&quot;:0,</span><br><span class="line">	&quot;msg&quot;:&quot;好友查询&quot;,</span><br><span class="line">	&quot;data&quot;:</span><br><span class="line">	[</span><br><span class="line">    	&#123;</span><br><span class="line">			&quot;friend_id&quot; : &quot;5c8f5853268d7942f44c6705&quot;,</span><br><span class="line">			&quot;friend_nick&quot; : &quot;小粪球儿&quot;,</span><br><span class="line">			&quot;friend_remark&quot; : &quot;圆圆&quot;,</span><br><span class="line">			&quot;friend_avatar&quot; : &quot;toy.jpg&quot;,</span><br><span class="line">			&quot;friend_chat&quot; : &quot;5c8f5853268d7942f44c6704&quot;,</span><br><span class="line">			&quot;friend_type&quot; : &quot;toy&quot;</span><br><span class="line">		&#125;</span><br><span class="line">	]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">1、从user表里找到对应的用户信息</span><br><span class="line">2、拿出用户信息里面的friend_list数据进行返回</span><br></pre></td></tr></table></figure>

<p>2、add_req</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">用于请求添加好友</span><br><span class="line"></span><br><span class="line">URL地址:	 /add_req</span><br><span class="line">请求方式:	POST</span><br><span class="line">请求协议:</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">    &quot;req_user&quot;:req_user_id, //发送好友请求方Id</span><br><span class="line">    &quot;add_user&quot;:add_user_id, //被请求方Id</span><br><span class="line">    &quot;type&quot;:app/toy, //请求方客户端类型</span><br><span class="line">    &quot;req_info&quot;:&quot;我是xxx&quot;, //请求内容信息</span><br><span class="line">    &quot;remark&quot;:remark //请求方 对 被请求方 的备注名称</span><br><span class="line">&#125;</span><br><span class="line">响应数据:</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">	&quot;code&quot;:0,</span><br><span class="line">	&quot;msg&quot;:&quot;添加好友请求成功&quot;,</span><br><span class="line">	&quot;data&quot;:&#123;&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">1、判断好友的类型：</span><br><span class="line">	整一个数据类型，不管是哪个好友度可以使用</span><br><span class="line">2、返回数据类型的整合</span><br><span class="line">3、放回数据类型</span><br></pre></td></tr></table></figure>

<p>3、rep_list</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">用于App查询绑定Toy的好友请求</span><br><span class="line"></span><br><span class="line">URL地址:	 /req_list</span><br><span class="line">请求方式:	POST</span><br><span class="line">请求协议:</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">    &quot;_id&quot;:user_id, //app用户Id</span><br><span class="line">&#125;</span><br><span class="line">响应数据:</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">	&quot;code&quot;:0,</span><br><span class="line">	&quot;msg&quot;:&quot;查询好友请求&quot;,</span><br><span class="line">	&quot;data&quot;:</span><br><span class="line">	[</span><br><span class="line">		&#123;</span><br><span class="line">            &quot;req_user&quot;:req_user_id, //发送好友请求方Id</span><br><span class="line">            &quot;add_user&quot;:add_user_id, //被请求方Id</span><br><span class="line">            &quot;type&quot;:app/toy, //请求方客户端类型</span><br><span class="line">            &quot;req_info&quot;:&quot;我是xxx&quot;, //请求内容信息</span><br><span class="line">            &quot;remark&quot;:remark //请求方 对 被请求方 的备注名称</span><br><span class="line">            &quot;avatar&quot;:avatar.jpg // 请求方的头像</span><br><span class="line">            &quot;nickname&quot;:&quot;nickname&quot; // 请求方的昵称</span><br><span class="line">            &quot;status&quot;:0 // 请求状态 0待处理 1同意 2拒绝</span><br><span class="line">            &quot;toy_name&quot;:&quot;toy_name&quot; // 被请求方的昵称</span><br><span class="line">		&#125;</span><br><span class="line">	]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">1、拿出uid</span><br><span class="line">2、根据uid查到bind_toys</span><br><span class="line">3、从requsetl列表里找出app绑定toys的请求信息</span><br><span class="line">4、将信息进行返回</span><br></pre></td></tr></table></figure>

<p>4、acc_rep</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">用于App同意绑定Toy被添加为好友</span><br><span class="line"></span><br><span class="line">URL地址:	 /acc_req</span><br><span class="line">请求方式:	POST</span><br><span class="line">请求协议:</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">    &quot;req_id&quot;:req_id, //好友请求信息Id</span><br><span class="line">    &quot;remark&quot;:&quot;friend_remark&quot;, //为请求方添加备注名称</span><br><span class="line">&#125;</span><br><span class="line">响应数据:</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">	&quot;code&quot;:0,</span><br><span class="line">	&quot;msg&quot;:&quot;同意添加好友&quot;,</span><br><span class="line">	&quot;data&quot;:&#123;&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">1、根据rep_id找到对应的好友请求</span><br><span class="line">2、双方交换名片</span><br><span class="line">3、更改request表里面status的状态</span><br></pre></td></tr></table></figure>

<p>5、拒绝好友请求  ref_req</p>
<p>用于App拒绝绑定Toy被添加为好友</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">URL地址:	 /ref_req</span><br><span class="line">请求方式:	POST</span><br><span class="line">请求协议:</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">    &quot;req_id&quot;:req_id //好友请求信息Id</span><br><span class="line">&#125;</span><br><span class="line">响应数据:</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">	&quot;code&quot;:0,</span><br><span class="line">	&quot;msg&quot;:&quot;拒绝添加好友&quot;,</span><br><span class="line">	&quot;data&quot;:&#123;&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">1、找到对应的好友请求</span><br><span class="line">2、将状态更改为0</span><br></pre></td></tr></table></figure>

<h2 id="五、智能玩具webSocket通讯"><a href="#五、智能玩具webSocket通讯" class="headerlink" title="五、智能玩具webSocket通讯"></a>五、智能玩具webSocket通讯</h2><h3 id="5-1-App通讯"><a href="#5-1-App通讯" class="headerlink" title="5.1 App通讯"></a>5.1 App通讯</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">#### WebSocket连接地址:</span><br><span class="line">ws://10.0.0.1:9528/app/&lt;user_id&gt;</span><br><span class="line">向Toy推送音乐:</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">	to_user: toy_id,	// 接收音乐的方ID</span><br><span class="line">    music: music_name	// 发送的音乐名称</span><br><span class="line">&#125;</span><br><span class="line">向Toy推送语音消息:</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">    chat: chat_file_name, // 语音文件名</span><br><span class="line">    to_user: toy_id, // 接收语音消息方ID</span><br><span class="line">    from_user: user_id // 发送语音消息方ID</span><br><span class="line">&#125;</span><br><span class="line"> 接收Toy发送的语音消息:</span><br><span class="line"> JSON:</span><br><span class="line">&#123;</span><br><span class="line">    chat: chat_file_name, // 语音文件名</span><br><span class="line">    to_user: toy_id, // 接收语音消息方ID</span><br><span class="line">    from_user: user_id // 发送语音消息方ID</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">就是websocket实现私聊</span><br></pre></td></tr></table></figure>

<h3 id="5-2-toy-通讯"><a href="#5-2-toy-通讯" class="headerlink" title="5.2 toy 通讯"></a>5.2 toy 通讯</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">WebSocket连接地址:</span><br><span class="line"></span><br><span class="line">ws://10.0.0.1:9528/toy/&lt;toy_id&gt;</span><br><span class="line"></span><br><span class="line">接收App推送音乐:</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">	to_user: toy_id,	// 接收音乐的方ID</span><br><span class="line">    music: music_name	// 发送的音乐名称</span><br><span class="line">&#125;</span><br><span class="line"> 接收App推送语音消息:</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">    chat: [&quot;chat&quot;,&quot;chat&quot;], // 语音文件名列表</span><br><span class="line">    to_user: toy_id, // 接收语音消息方ID</span><br><span class="line">    from_user: user_id // 发送语音消息方ID</span><br><span class="line">&#125;</span><br><span class="line"> 向App推送语音消息:</span><br><span class="line">JSON:</span><br><span class="line">&#123;</span><br><span class="line">    chat: chat_file_name, // 语音文件名</span><br><span class="line">    to_user: toy_id, // 接收语音消息方ID</span><br><span class="line">    from_user: user_id // 发送语音消息方ID</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">就是websocket实现私聊</span><br></pre></td></tr></table></figure>

<h2 id="六、-函数类"><a href="#六、-函数类" class="headerlink" title="六、 函数类"></a>六、 函数类</h2><h3 id="6-1未读消息提醒类"><a href="#6-1未读消息提醒类" class="headerlink" title="6.1未读消息提醒类"></a>6.1未读消息提醒类</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">def get_xxtx(to_user,from_user,tx_type=None):</span><br><span class="line">    friend_remark = &quot;未知用户&quot;</span><br><span class="line">    toy_info = DB.Toys.find_one(&#123;&quot;_id&quot;: ObjectId(to_user)&#125;)</span><br><span class="line">    toy_friend_list = toy_info.get(&quot;friend_list&quot;)</span><br><span class="line">    for friend in toy_friend_list:</span><br><span class="line">        if friend.get(&quot;friend_id&quot;) == from_user:</span><br><span class="line">            friend_remark = friend.get(&quot;friend_remark&quot;)</span><br><span class="line">            friend_type = friend.get(&quot;friend_type&quot;)</span><br><span class="line"></span><br><span class="line">    if tx_type == &quot;xxtx&quot;:</span><br><span class="line">        wenjianming = text2audio(f&quot;你有来自&#123;friend_remark&#125;的消息&quot;)</span><br><span class="line">        return wenjianming</span><br><span class="line">    else:</span><br><span class="line">        wenjianming = text2audio(f&quot;以下是来自&#123;friend_remark&#125;的消息&quot;)</span><br><span class="line">        return wenjianming,friend_type</span><br><span class="line">用于区分是rec_msg get_chat的</span><br></pre></td></tr></table></figure>

<h3 id="6-2未读消息类"><a href="#6-2未读消息类" class="headerlink" title="6.2未读消息类"></a>6.2未读消息类</h3><p>1、储存未读消息</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">set_redis</span><span class="params">(to_user,from_user)</span>:</span></span><br><span class="line">    print(to_user)</span><br><span class="line">    to_user_json = RDB.get(to_user)</span><br><span class="line">    <span class="keyword">if</span> to_user_json:</span><br><span class="line">        to_user_dict = json.loads(to_user_json)</span><br><span class="line">        <span class="keyword">if</span> to_user_dict.get(from_user):</span><br><span class="line">            to_user_dict[from_user] += <span class="number">1</span></span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            to_user_dict[from_user] = <span class="number">1</span></span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        to_user_dict =&#123;from_user:<span class="number">1</span>&#125;</span><br><span class="line"></span><br><span class="line">    to_user_json = json.dumps(to_user_dict)</span><br><span class="line">    RDB.set(to_user,to_user_json)</span><br></pre></td></tr></table></figure>

<p>2、获取单个用户未读消息</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">get_redis</span><span class="params">(to_user,from_user)</span>:</span></span><br><span class="line">    to_user_json = RDB.get(to_user)</span><br><span class="line">    print(<span class="string">"to_user"</span>)</span><br><span class="line">    <span class="keyword">if</span> to_user_json:</span><br><span class="line">        to_user_dict = json.loads(to_user_json)</span><br><span class="line"></span><br><span class="line">        count = to_user_dict.pop(from_user,<span class="number">0</span>)</span><br><span class="line">        to_user_dict[from_user] = <span class="number">0</span></span><br><span class="line">        to_user_json =json.dumps(to_user_dict)</span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        to_user_json = json.dumps(&#123;from_user: <span class="number">0</span>&#125;)</span><br><span class="line">        count =<span class="number">0</span></span><br><span class="line">    RDB.set(to_user, to_user_json)</span><br><span class="line">    <span class="keyword">return</span> count</span><br></pre></td></tr></table></figure>

<p>3、获取所有未读消息数</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">def get_all_redis(to_user):</span><br><span class="line">    to_user_json = RDB.get(to_user)</span><br><span class="line">    if to_user_json:</span><br><span class="line">        to_user_dict = json.loads(to_user_json)  # type:dict</span><br><span class="line">        to_user_dict[&quot;count&quot;] = sum(to_user_dict.values())</span><br><span class="line">    else:</span><br><span class="line">        to_user_dict = &#123;&quot;count&quot;: 0&#125;</span><br><span class="line"></span><br><span class="line">    print(to_user_dict)</span><br><span class="line">    return to_user_dict</span><br><span class="line">    </span><br><span class="line">针对 app用户</span><br></pre></td></tr></table></figure>

<p>4、toy未读消息数</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">def get_redis_toy(to_user, from_user):</span><br><span class="line">    to_user_json = RDB.get(to_user)</span><br><span class="line">    if to_user_json:</span><br><span class="line">        to_user_dict = json.loads(to_user_json)</span><br><span class="line">        count = to_user_dict.pop(from_user, 0)</span><br><span class="line">        if count == 0:</span><br><span class="line">            for k, v in to_user_dict.items():</span><br><span class="line">                if v:</span><br><span class="line">                    from_user = k</span><br><span class="line">                    count = v</span><br><span class="line">        to_user_dict[from_user] = 0</span><br><span class="line">        to_user_json = json.dumps(to_user_dict)</span><br><span class="line">    else:</span><br><span class="line">        to_user_json = json.dumps(&#123;from_user: 0&#125;)</span><br><span class="line">        count = 0</span><br><span class="line">    RDB.set(to_user, to_user_json)</span><br><span class="line"></span><br><span class="line">    return count,from_user</span><br></pre></td></tr></table></figure>

<h2 id="六-百度ai智能语音"><a href="#六-百度ai智能语音" class="headerlink" title="六 百度ai智能语音"></a>六 百度ai智能语音</h2><p>1、文件格式转换</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">def get_file_content(file_path):</span><br><span class="line">    cmd_str = f&quot;ffmpeg -y -i &#123;file_path&#125; -acodec pcm_s16le -f s16le -ac 1 -ar 16000 &#123;file_path&#125;.pcm&quot;</span><br><span class="line">    os.system(cmd_str)</span><br><span class="line">    with open(f&quot;&#123;file_path&#125;.pcm&quot;,&quot;rb&quot;) as fp:</span><br><span class="line">        return fp.read()</span><br></pre></td></tr></table></figure>

<p>2、音频转文字</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">def atudio2text(file_path):</span><br><span class="line">    file_content = get_file_content(file_path)</span><br><span class="line">    res = SPEECH_CLIENT.asr(file_content,&quot;pcm&quot;, 16000, &#123;&quot;dev_pid&quot;: 1536&#125;)</span><br><span class="line">    print(res)</span><br><span class="line">    return res.get(&quot;result&quot;)[0]</span><br></pre></td></tr></table></figure>

<p>3、文字转音频</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">text2audio</span><span class="params">(A)</span>:</span></span><br><span class="line">    res = SPEECH_CLIENT.synthesis(A,<span class="string">"zh"</span>,<span class="number">1</span>,VIOCE)</span><br><span class="line">    file_name = <span class="string">f"<span class="subst">&#123;uuid4()&#125;</span>.mp3"</span></span><br><span class="line">    file_path =os.path.join(VOICE_PATH,file_name)</span><br><span class="line">    <span class="keyword">if</span> type(res) ==dict:</span><br><span class="line">        <span class="keyword">pass</span></span><br><span class="line">    <span class="keyword">with</span> open(file_path,<span class="string">"wb"</span>) <span class="keyword">as</span> f:</span><br><span class="line">        f.write(res)</span><br><span class="line">    <span class="keyword">return</span> file_name</span><br></pre></td></tr></table></figure>

<p>4、nlp语言处理</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">my_nlp</span><span class="params">(Q,toy_id)</span>:</span></span><br><span class="line">    print(toy_id)</span><br><span class="line">    <span class="keyword">if</span> <span class="string">"我要听"</span> <span class="keyword">in</span> Q <span class="keyword">or</span> <span class="string">"我想听"</span> <span class="keyword">in</span> Q <span class="keyword">or</span> <span class="string">"请播放"</span> <span class="keyword">in</span> Q :</span><br><span class="line">        print(<span class="string">"222"</span>)</span><br><span class="line">        content = my_nlp_content(Q)</span><br><span class="line">        print(content)</span><br><span class="line">        <span class="keyword">if</span> content:</span><br><span class="line">            <span class="keyword">return</span> &#123;<span class="string">"from_user"</span>: <span class="string">"ai"</span>, <span class="string">"music"</span>: content.get(<span class="string">"music"</span>)&#125;</span><br><span class="line">    <span class="keyword">if</span> <span class="string">"发消息"</span> <span class="keyword">in</span> Q:</span><br><span class="line">        print(<span class="number">1</span>)</span><br><span class="line">        toy_info = DB.Toys.find_one(&#123;<span class="string">"_id"</span>: ObjectId(toy_id)&#125;)</span><br><span class="line">        <span class="keyword">for</span> friend <span class="keyword">in</span> toy_info.get(<span class="string">"friend_list"</span>):</span><br><span class="line">            Q_py = <span class="string">""</span>.join(lazy_pinyin(Q, style=TONE2))</span><br><span class="line">            toy_info = DB.Toys.find_one(&#123;<span class="string">"_id"</span>: ObjectId(toy_id)&#125;)</span><br><span class="line">            <span class="keyword">for</span> friend <span class="keyword">in</span> toy_info.get(<span class="string">"friend_list"</span>):</span><br><span class="line">                re_py = <span class="string">""</span>.join(lazy_pinyin(friend.get(<span class="string">"friend_remark"</span>), style=TONE2))</span><br><span class="line">                ni_py = <span class="string">""</span>.join(lazy_pinyin(friend.get(<span class="string">"friend_nick"</span>), style=TONE2))</span><br><span class="line">                print(<span class="number">2</span>)</span><br><span class="line">                print(<span class="string">"re_py"</span>,re_py)</span><br><span class="line">                print(<span class="string">"Q_py"</span>,Q_py)</span><br><span class="line">                print(<span class="string">"ni_py"</span>,ni_py)</span><br><span class="line">                <span class="keyword">if</span> re_py <span class="keyword">in</span> Q_py <span class="keyword">or</span> ni_py <span class="keyword">in</span> Q_py:</span><br><span class="line">                    print(<span class="number">3</span>)</span><br><span class="line">                    filename = text2audio(<span class="string">f"现在可以给<span class="subst">&#123;friend.get(<span class="string">'friend_remark'</span>)&#125;</span>发消息了"</span>)</span><br><span class="line">                    <span class="keyword">return</span> &#123;</span><br><span class="line">                        <span class="string">"from_user"</span>: friend.get(<span class="string">"friend_id"</span>),</span><br><span class="line">                        <span class="string">"chat"</span>: filename,</span><br><span class="line">                        <span class="string">"friend_type"</span>: friend.get(<span class="string">"friend_type"</span>)</span><br><span class="line">                    &#125;</span><br><span class="line">                <span class="keyword">else</span>:</span><br><span class="line">                    filename = text2audio(<span class="string">"我没听清楚,请再说一次"</span>)</span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        print(<span class="number">5</span>)</span><br><span class="line">        filename = text2audio(<span class="string">"我没听清楚,请再说一次"</span>)</span><br></pre></td></tr></table></figure>

<h2 id="七-私聊的-websocket"><a href="#七-私聊的-websocket" class="headerlink" title="七 私聊的 websocket"></a>七 私聊的 websocket</h2><p>后端代码：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> json</span><br><span class="line"></span><br><span class="line"><span class="keyword">from</span> flask <span class="keyword">import</span> Flask,request,render_template,jsonify</span><br><span class="line"><span class="keyword">from</span> geventwebsocket.handler <span class="keyword">import</span> WebSocketHandler</span><br><span class="line"><span class="keyword">from</span> geventwebsocket.server <span class="keyword">import</span> WSGIServer</span><br><span class="line"><span class="keyword">from</span> geventwebsocket.websocket <span class="keyword">import</span> WebSocket</span><br><span class="line"><span class="keyword">from</span> settings <span class="keyword">import</span> DB</span><br><span class="line">ws_app = Flask(__name__)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 实现聊天</span></span><br><span class="line">user_socket_dict=&#123;&#125;</span><br><span class="line"><span class="meta">@ws_app.route("/app/&lt;user_id&gt;")</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">wsapp</span><span class="params">(user_id)</span>:</span></span><br><span class="line">    user_scoket = request.environ.get(<span class="string">"wsgi.websocket"</span>)</span><br><span class="line">    <span class="keyword">if</span> user_scoket:</span><br><span class="line">        user_socket_dict[user_id]= user_scoket</span><br><span class="line">    print(user_socket_dict)</span><br><span class="line">    <span class="keyword">while</span> <span class="number">1</span>:</span><br><span class="line">        msg = user_scoket.receive()</span><br><span class="line">        msg_dict = json.loads(msg)</span><br><span class="line">        to_user = msg_dict.get(<span class="string">"to_user"</span>)  <span class="comment">#要发给的人</span></span><br><span class="line">        user_scoket = user_socket_dict.get(to_user)</span><br><span class="line">        user_scoket.send(msg)</span><br><span class="line"></span><br><span class="line"><span class="meta">@ws_app.route("/toy/&lt;toy_id&gt;")</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">wstoy</span><span class="params">(toy_id)</span>:</span></span><br><span class="line">    user_scoket = request.environ.get(<span class="string">"wsgi.websocket"</span>)</span><br><span class="line">    <span class="keyword">if</span> user_scoket:</span><br><span class="line">        user_socket_dict[toy_id]= user_scoket</span><br><span class="line">    print(user_socket_dict)</span><br><span class="line">    <span class="keyword">while</span> <span class="number">1</span>:</span><br><span class="line">        msg = user_scoket.receive()</span><br><span class="line">        msg_dict = json.loads(msg)</span><br><span class="line">        to_user = msg_dict.get(<span class="string">"to_user"</span>) <span class="comment">#</span></span><br><span class="line">        user_scoket =user_socket_dict.get(to_user)</span><br><span class="line">        user_scoket.send(msg)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="meta">@ws_app.route("/get_toy")</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">get_toy</span><span class="params">()</span>:</span></span><br><span class="line">    <span class="keyword">return</span> render_template(<span class="string">"WebToy.html"</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">'__main__'</span>:</span><br><span class="line">    http_server = WSGIServer((<span class="string">"0.0.0.0"</span>,<span class="number">5001</span>),ws_app,handler_class= WebSocketHandler)</span><br><span class="line">    http_server.serve_forever()</span><br></pre></td></tr></table></figure>

<h2 id="八、-吧注意事项"><a href="#八、-吧注意事项" class="headerlink" title="八、 吧注意事项"></a>八、 吧注意事项</h2><p>跨域问题方案的解决：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>、安装flask_cors模块</span><br><span class="line"><span class="number">2</span>、<span class="keyword">from</span> flask_cors <span class="keyword">import</span> CORS</span><br><span class="line"><span class="number">3</span>、app =Flask(__name__)</span><br><span class="line">	CORS(app)</span><br></pre></td></tr></table></figure>

<h2 id="九、其他技术点"><a href="#九、其他技术点" class="headerlink" title="九、其他技术点"></a>九、其他技术点</h2><p>1、跨域问题的解决</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> flask_cors <span class="keyword">import</span> CORS</span><br><span class="line">CORS(app) <span class="comment"># 跨域请求解决方案 Flask-CORS</span></span><br></pre></td></tr></table></figure>


      
    </div>
    
    
    

    

    

    
      <div>
        <ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者：</strong>
    
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="http://yoursite.com/2019/09/20/【面试题】04-2智能玩具开发 - 副本/" title="智能玩具项目复习">http://yoursite.com/2019/09/20/【面试题】04-2智能玩具开发 - 副本/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>
    本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/3.0/" rel="external nofollow" target="_blank">CC BY-NC-SA 3.0</a> 许可协议。转载请注明出处！
  </li>
</ul>

      </div>
    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/dxl/tags/面试题/" rel="tag"># 面试题</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/dxl/2019/09/20/【面试题】04-1crm项目复习/" rel="next" title="crm项目复习">
                <i class="fa fa-chevron-left"></i> crm项目复习
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/dxl/2019/09/20/【面试题】04-3权限模式 - 副本/" rel="prev" title="权限复习">
                权限复习 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
    </div>
  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/dxl/images/avatar.png" alt>
            
              <p class="site-author-name" itemprop="name"></p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/dxl/archives">
              
                  <span class="site-state-item-count">43</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/dxl/categories/index.html">
                  <span class="site-state-item-count">6</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/dxl/tags/index.html">
                  <span class="site-state-item-count">6</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-inline">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-sign-out"></i>
                我的友链
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="tencent://message/?Menu=yes&uin=1258517737&Site=QQ%E6%9E%81%E5%AE%A2&Service=300&sigT=45a1e5847943b64c6ff3990f8a9e644d2b31356cb0b4ac6b24663a3c8dd0f8aa12a595b1714f9d45/" title="申请坑位" target="_blank">申请坑位</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#一、需要用到的模块和知识"><span class="nav-number">1.</span> <span class="nav-text">一、需要用到的模块和知识</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#二、需求分析"><span class="nav-number">2.</span> <span class="nav-text">二、需求分析</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#三、数据库"><span class="nav-number">3.</span> <span class="nav-text">三、数据库</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1有哪些表"><span class="nav-number">3.1.</span> <span class="nav-text">3.1有哪些表</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2Users"><span class="nav-number">3.2.</span> <span class="nav-text">3.2Users</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-3-Toys"><span class="nav-number">3.3.</span> <span class="nav-text">3.3 Toys</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-4-Request"><span class="nav-number">3.4.</span> <span class="nav-text">3.4 Request</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-5-Devices"><span class="nav-number">3.5.</span> <span class="nav-text">3.5 Devices</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-6-Content"><span class="nav-number">3.6.</span> <span class="nav-text">3.6 Content</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-7-Chats"><span class="nav-number">3.7.</span> <span class="nav-text">3.7 Chats</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#四、业务逻辑分析与处理（Api）"><span class="nav-number">4.</span> <span class="nav-text">四、业务逻辑分析与处理（Api）</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#4-1-用户（登录、注册）"><span class="nav-number">4.1.</span> <span class="nav-text">4.1 用户（登录、注册）</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-2设备"><span class="nav-number">4.2.</span> <span class="nav-text">4.2设备</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-3设备启动登录接口"><span class="nav-number">4.3.</span> <span class="nav-text">4.3设备启动登录接口:</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-4内容相关"><span class="nav-number">4.4.</span> <span class="nav-text">4.4内容相关</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-5音频上传先关联"><span class="nav-number">4.5.</span> <span class="nav-text">4.5音频上传先关联</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-6语音消息相关"><span class="nav-number">4.6.</span> <span class="nav-text">4.6语音消息相关</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-7好友通讯相关"><span class="nav-number">4.7.</span> <span class="nav-text">4.7好友通讯相关</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#五、智能玩具webSocket通讯"><span class="nav-number">5.</span> <span class="nav-text">五、智能玩具webSocket通讯</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#5-1-App通讯"><span class="nav-number">5.1.</span> <span class="nav-text">5.1 App通讯</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-2-toy-通讯"><span class="nav-number">5.2.</span> <span class="nav-text">5.2 toy 通讯</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#六、-函数类"><span class="nav-number">6.</span> <span class="nav-text">六、 函数类</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#6-1未读消息提醒类"><span class="nav-number">6.1.</span> <span class="nav-text">6.1未读消息提醒类</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-2未读消息类"><span class="nav-number">6.2.</span> <span class="nav-text">6.2未读消息类</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#六-百度ai智能语音"><span class="nav-number">7.</span> <span class="nav-text">六 百度ai智能语音</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#七-私聊的-websocket"><span class="nav-number">8.</span> <span class="nav-text">七 私聊的 websocket</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#八、-吧注意事项"><span class="nav-number">9.</span> <span class="nav-text">八、 吧注意事项</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#九、其他技术点"><span class="nav-number">10.</span> <span class="nav-text">九、其他技术点</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
            <span id="scrollpercent"><span>0</span>%</span>
          
        </div>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-hand-peace-o"></i>
  </span>
  <span class="author" itemprop="copyrightHolder"></span>

  
</div>









        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      本站访客数
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      人次
    </span>
  

  
    <span class="site-pv">
      本站总访问量
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      次
    </span>
  
</div>








        
      </div>
    </footer>

    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/dxl/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/dxl/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/dxl/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/dxl/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/dxl/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/dxl/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/dxl/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/dxl/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/dxl/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/dxl/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/dxl/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/dxl/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/dxl/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  










  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//unpkg.com/valine/dist/Valine.min.js"></script>
  
  <script type="text/javascript">
    var GUEST = ['nick','mail','link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item=>{
      return GUEST.indexOf(item)>-1;
    });
    new Valine({
        el: '#comments' ,
        verify: false,
        notify: false,
        appId: '13B0JGDuA6ttduN8AQaR8CzF-gzGzoHsz',
        appKey: 'I13r9r5mVgq4jQYpYy6V4gW3',
        placeholder: '欢迎大佬指点~~~',
        avatar:'mm',
        guest_info:guest,
        pageSize:'10' || 10,
    });
  </script>



  





  

  

  

  
  

  

  

  

</body>
</html>
